package com.frxuexi.lib_base.room

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = [User::class], version = 1, exportSchema = false)
abstract class AppDataBase:RoomDatabase() {
    abstract fun userDao():UserDao

    companion object{

        @Volatile
        private var appDataBase:AppDataBase?=null

        fun getInstance(context: Context):AppDataBase
        = appDataBase?: synchronized(this){
            appDataBase?: buildDataBase(context = context)
        }

        fun buildDataBase(context: Context):AppDataBase{
            return Room.databaseBuilder(context,AppDataBase::class.java,"mymdm2202")
                .build()
        }
    }
}